package com.wxd.framework.common.data;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateHelper {

	/**
	 * 获取当前时间
	 * @return
	 */
	public static String NowTimeString() {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return df.format(new Date());
	}
	
	/**
	 * 获取当前日期
	 * @return
	 */
	public static String NowDateString() {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(new Date());
	}
	
	/**
	 * 获取当前年份
	 * @return
	 */
	public static int getCurrYear(){
		Calendar now = Calendar.getInstance(); 
		return now.get(Calendar.YEAR);
	} 
	
	/**
	 * 获取当前月
	 * @return
	 */
	public static int getCurrMonth(){
		Calendar now = Calendar.getInstance(); 
		return now.get(Calendar.MONTH)+1;
	}
	
	/**
	 * 获取当前日
	 * @return
	 */
	public static int getCurrDay(){
		Calendar now = Calendar.getInstance(); 
		return now.get(Calendar.DAY_OF_MONTH);
	} 
	
	/** 
     * 得到几天前的时间 
     *  
     * @param d 
     * @param day 
     * @return 
     */  
    public static String getDateBefore(Date d, int day) {  
        Calendar now = Calendar.getInstance();  
        now.setTime(d);  
        now.set(Calendar.DATE, now.get(Calendar.DATE) - day);  
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(now.getTime());
    }  
  
    /** 
     * 得到几天后的时间 
     *  
     * @param d 
     * @param day 
     * @return 
     */  
    public static String getDateAfter(Date d, int day) {  
        Calendar now = Calendar.getInstance();  
        now.setTime(d);  
        now.set(Calendar.DATE, now.get(Calendar.DATE) + day);  
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(now.getTime());
    } 
}
